﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CarLeasing.Forms.Controls
{
    public partial class DropDownFilter : UserControl
    {
        public DropDownFilter():
            this("Text", new string[0])
        { }

        public DropDownFilter(string text, string[] values)
        {
            InitializeComponent();

            SetFilter(text, values);
        }

        public void SetFilter(string text, string[] values)
        {
            label_Name.Text = $"{text}: ";
            comboBox_Values.Items.Clear();
            comboBox_Values.Items.AddRange(values.Distinct().Concat(new[] { "任何" }).ToArray());
            comboBox_Values.SelectedIndex = comboBox_Values.Items.Count - 1;
        }

        public Func<string, bool> Filter
        {
            get
            {
                var any = comboBox_Values.SelectedIndex == comboBox_Values.Items.Count - 1;
                return str => any || str == comboBox_Values.SelectedItem.ToString();
            }
        }
    }
}
